package IO.file;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomFile {
    public static void main(String[] args) {
        try {
            File d = new File("test.file");
            if (!d.exists()) {
                d.createNewFile();
            }
            RandomAccessFile file = new RandomAccessFile(d, "rw");
            file.writeChars("hello world");
            file.seek(0);
            byte[] b = new byte[(int) file.length() - 10];
            file.read(b);
            System.out.println(new String(b));
            d.delete();
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
